package com.qiche.controller;

import com.alibaba.fastjson.JSON;
import com.github.pagehelper.PageInfo;
import com.google.zxing.client.j2se.MatrixToImageWriter;
import com.google.zxing.common.BitMatrix;
import com.qiche.aspect.Result;
import com.qiche.constant.AccountType;
import com.qiche.dto.MemberCardDto;
import com.qiche.dto.MemberCardItemDto;
import com.qiche.dto.MerchantDto;
import com.qiche.enums.ResultEnum;
import com.qiche.model.*;
import com.qiche.qrcode.QRCodeUtils;
import com.qiche.service.*;
import com.qiche.service2.*;
import com.qiche.util.JsonRpcUtils;
import com.qiche.util.UserUtils;
import com.qiche.vo.CardDetailsVo;
import com.qiche.vo.CardVo;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.SecurityUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * 评价留言管理控制器
 */
@RestController
@RequestMapping("/evaluation")
public class EvaluationController {
    @Autowired
    private EvaluationService evaluationService;

    /**
     * 提交留言
     *
     * @param evaluation
     * @return
     */
    @PostMapping("/submit")
    public Result submit(@RequestBody Evaluation evaluation) {
        int saveCount = evaluationService.save(evaluation);
        if (saveCount > 0) {
            return Result.createBySuccessMessage("留言成功");
        }
        return Result.createByErrorMessage("留言失败");

    }

    @ApiOperation(value ="根据条件和分页获取评价列表" )
    @GetMapping
    public Map<String, Object> getAll(@RequestParam(required = false, defaultValue = "1") int page,
                                      @RequestParam(required = false, defaultValue = "10") int limit) {
        Map<String, Object> map = new HashMap<>();
        PageInfo<Evaluation> pageInfo = evaluationService.selectByPage(page, limit);
        map.put("code", 0);
        map.put("msg", "查询成功");
        map.put("count", pageInfo.getTotal());
        map.put("data", pageInfo.getList());
        return map;
    }


}
